#include <iostream>
#include <memory>

class Simple {
public:
  void toString() { std::cout << "xxx\n"; }
};

void useResource(std::weak_ptr<Simple> &weakSimple) {
  auto resource = weakSimple.lock();
  if (resource) {
    std::cout << "Resource is still alive.\n";
  } else {
    std::cout << "Resource has been freed.\n";
  }
}

int main() {
  auto shared_simple{std::make_shared<Simple>()};
  std::weak_ptr<Simple> weak_simple{shared_simple};

  useResource(weak_simple);

  shared_simple.reset();

  useResource(weak_simple);
}